package org.codegallery.javagal.concurrent.jcip.c6;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.Executors;

import javax.swing.JButton;
import javax.swing.JFrame;

public class InfiniteLoopFrameTest {
	public static void main(String[] args){
		JFrame f=new JFrame();
		FlowLayout layout=new FlowLayout();
		f.setLayout(layout);
		JButton jbtnOk=new JButton("OK");
		JButton jbtnCancel=new JButton("Cancel");
		jbtnOk.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				long count=0;
				while(true){
					int second=Calendar.getInstance().get(Calendar.SECOND);
					int milliseSecond=Calendar.getInstance().get(Calendar.MILLISECOND);
					
					
					if(milliseSecond % 500==0 && second % 5==0){
						if(count %200 ==0){
							System.out.println(new Date());
						}else{
							count=count+1;
							if(count>201){
								count=0;
							}
							
						}
						
					}
				}	
//				Runnable r=new Runnable(){
//					public void run(){
//						long count=0;
//						while(true){
//							int second=Calendar.getInstance().get(Calendar.SECOND);
//							int milliseSecond=Calendar.getInstance().get(Calendar.MILLISECOND);
//							
//							
//							if(milliseSecond % 500==0 && second % 5==0){
//								if(count %200 ==0){
//									System.out.println(new Date());
//								}else{
//									count=count+1;
//									if(count>201){
//										count=0;
//									}
//									
//								}
//								
//							}
//						}
//					}
//				};
//				//Executors.newSingleThreadExecutor();
//				new Thread(r).start();
				
			}
			
		});
		jbtnCancel.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				System.out.println("Cancel Button Canceled....");
				
			}
			
		});
		f.add(jbtnOk);
		f.add(jbtnCancel);
		f.pack();
		f.setVisible(true);
	}

}
